<!--
* description: 电池退役门店
* author: xuliwen
* createdDate: 2021-01-21
-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :key="oneTableKey"
      :dynamic-buttons="tableButtons"
      :dynamic-components="tableComponents"
      :dynamic-api-config="apiConfig"
      :dynamic-table-cols="tableCols"
      :dynamic-form-fields="formField"
      :dynamic-is-show-select="false"
      :dynamic-is-init-table="true"
      :dynamic-api-style="'restful'"
    />

    <edit
      :key="editPopupsKey"
      :dynamic-edit-row-data="editRowData"
      :popups-visible="editPopupsVisible"
      :popups-state="editPopupsState"
      :dynamic-api-style="'restful'"
      @close="close"
    />
  </div>
</template>
<script>

import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import OneTableTemplate from '@/components/templates/oneTable'
import { exportExcel } from '@/utils/getTimeString.js'
import api from '@/api/se/apiBaseData'
import Vue from 'vue'

export default {
  name: 'retireBatteryMaintenance',

  components: {
    OneTableTemplate,
    Edit: () => import('./edit')
  },
  // 组件混入对象
  mixins: [oneTableWithViewTemplateMixins],

  // 阻塞路由预加载网格中组件的数据
  beforeRouteEnter(to, from, next) {
    Vue.prototype.$ConfigCache.CacheConfig.initData([to.path, ''], function() {
      next()
    })
  },

  data() {
    // 页面标识（与上面beforeRouteEnter中的对应）
    const viewPageCode = this.$route.path

    // 绑定事件配置化事件
    this.$ConfigCache.CacheConfig.bindEvent(this, [viewPageCode])

    return {
      editRowData: {},
      // 网格查询API配置对象
      apiConfig: api.queryBatteryRetiredByDir,
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: 'btnKey1',
          type: 'primary',
          size: 'small',
          name: 'search',
          clickEvent: () => this.queryTable(1),
          text: this.$t('sys.button.query'), // 查询
          position: 'right',
          fuzzySearch: true
        },
        {
          compKey: 'btnKey2',
          type: '',
          size: 'small',
          name: 'reset',
          clickEvent: () => this.reset(),
          text: this.$t('sys.button.reset'),
          position: 'right' // 重置
        },
        {
          compKey: 'btnKey3',
          type: '',
          size: 'small',
          name: 'add',
          clickEvent: this.add,
          text: this.$t('sys.button.add'), // 新增
          position: 'left'
        },
        // {
        //   compKey: 'btnKey4',
        //   type: 'primary',
        //   size: 'small',
        //   clickEvent: () => this.importcar(),
        //   text: '导入',
        //   name: 'import', // 按钮图标样式
        //   position: 'upload'
        // },
        // {
        //   compKey: 'btnKey5',
        //   type: '',
        //   size: 'small',
        //   clickEvent: () => this.download(),
        //   text: '下载模板',
        //   name: 'download',
        //   position: 'right'
        // },
        {
          compKey: 'btnKey3',
          type: '',
          size: 'small',
          clickEvent: () => this.exportExcel111(),
          text: '导出',
          name: 'export',
          position: 'left'
        }
      ],

      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
            .tableComponents
          : [
            {
                 compKey: 'compKey10',
                labelName: '登记日期：',
                codeField: 'createDateStart,createDateEnd',
                component: () => import('@/components/org/datePicker/andtDatePicker'),
                type:'YYYY-MM-DD',
                // dataToObject:{timer:true,thirtyTime:true,hhmmss: true},
                format: 'yyyy-MM-dd',
                isMul: false,
                isMust: true,
              },
            {
              compKey: 'compKey2',
              labelName: '派工单号：',
              codeField: 'repairOrderCode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: true
            },
              {
              compKey: 'compKey3',
              labelName: '电池编号：',
              codeField: 'batteryCode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: true
            },
          ],

      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
            {
              prop: 'releaseId',
              label: '电池退役信息ID',
              hidden: true,
              alwaysHidden: true
            },
            {
              prop: 'updateControlId',
              label: '并发控制ID',
              hidden: true,
              alwaysHidden: true
            },
            {
              prop: 'controlBtn1',
              label: '操作',
              minWidth: 180,
              isComponent: true,
              comps: [
                {
                  compKey: 'propKey1',
                  labelName: '修改',
                  rowFileds: 'show:isCommit--1',
                  component: () => import('@/components/org/linkButton'),
                  clickEvent: (index) => this.edit(index)
                }
              ]
            },
            {
              prop: 'batteryCode',
              label: '电池编号',
               width:'150px'
            },
            {
              prop: 'repairOrderCode',
              label: '派工单号',
              width:'100px'
            },

            {
              prop: 'vin',
              label: 'VIN',
               width:'150px'
            },
            {
              prop: 'whereaboutsName',
              label: '退役去向厂商名称',
               width:'150px'
            },
            {
              prop: 'whereaboutsCode',
              label: '退役去向厂商统一社会信用代码',
               width:'150px'
            },
            {
              prop: 'retireUnitName',
              label: '退役厂商名称',
               width:'150px'
            },
            {
              prop: 'retireUnitCode',
              label: '退役厂商统一社会信用代码',
               width:'150px'
            },
             {
                prop: "batteryTypeName",
                label: "电池类型",
              },
              {
                prop: "factoryTypeName",
                label: "退役企业类型",
              },
              {
                prop: "batteryWeight",
                label: "电池质量",
              },
               {
                prop: "createdDate",
                label: "登记日期",
                width:'150px'
              },
            {
              prop: 'creator',
              label: '登记人'
            },
          ],

      // 表单查询数据
      formField: this.$utils.getFormField(this, {
          createDateStart:'',
          createDateEnd:'',
          repairOrderCode:'',
          batteryCode:''
      }, this.$ConfigCache.CacheConfig.cacheData[viewPageCode])
    }
  },

  mounted() {
    // 列表查询
    this.queryTable(1)
  },

  methods: {
    exportExcel111(){
      exportExcel(this.formField, api.batteryRetiredByDirExcel.APIUrl, api.batteryRetiredByDirExcel.ServiceCode, '电池退役维护查询')
      },
    // 编辑获取数据
    edit(index) {
      this.editPopupsState = 'edit'
      this.editPopupsVisible = true
      this.editRowData = this.$utils.deepCopy(this.$refs['multipleTable'].list[index])
    }
  }
}
</script>
